<!-- listing fields tpl -->

<!-- navigation bar -->
<div id="nav_bar">
	{rlHook name='apTplListingFieldsNavBar'}

	{if !isset($smarty.get.action)}
		<a href="javascript:void(0)" onclick="show('search', '#action_blocks div');" class="button_bar"><span class="left"></span><span class="center_search">{$lang.search}</span><span class="right"></span></a>
	{/if}
	
	{if $aRights.$cKey.add && $smarty.get.action != 'add'}
		<a href="{$rlBaseC}action=add" class="button_bar"><span class="left"></span><span class="center_add">{$lang.add_field}</span><span class="right"></span></a>
	{/if}
	
	<a href="{$rlBase}index.php?controller={$smarty.get.controller}" class="button_bar"><span class="left"></span><span class="center_list">{$lang.fields_list}</span><span class="right"></span></a>
</div>
<!-- navigation bar end -->

<div id="action_blocks">

	{if !isset($smarty.get.action)}
		<!-- search -->
		<div id="search" class="hide">
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'m_block_start.tpl' block_caption=$lang.search}
			
			<form method="post" onsubmit="return false;" id="search_form" action="">
			<table class="form">
			<tr>
				<td class="name">{$lang.name}</td>
				<td class="field"><input type="text" id="search_name" /></td>
			</tr>
			<tr>
				<td class="name">{$lang.field_type}</td>
				<td class="field">
					<select id="search_type" style="width: 200px;">
					<option value="">- {$lang.all} -</option>
					{foreach from=$l_types item='item' key='key'}
						<option value="{$key}">{$item}</option>
					{/foreach}
					</select>
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.required_field}</td>
				<td class="field" id="search_require_td">
					<label title="{$lang.unmark}"><input title="{$lang.unmark}" type="radio" id="required_uncheck" value="" /> ...</label>
					<label><input type="radio" name="search_required" id="required_yes" value="yes" /> {$lang.yes}</label>
					<label><input type="radio" name="search_required" id="required_no" value="no" /> {$lang.no}</label>
					
					<script type="text/javascript">
					{literal}
					$('#required_uncheck').click(function(){
						$('#search_require_td input').attr('checked', false);
					});
					{/literal}
					</script>
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.google_map}</td>
				<td class="field" id="search_gmap_td">
					<label title="{$lang.unmark}"><input title="{$lang.unmark}" type="radio" id="gmap_uncheck" value="" /> ...</label>
					<label><input type="radio" name="search_gmap" id="gmap_yes" value="yes" /> {$lang.yes}</label>
					<label><input type="radio" name="search_gmap" id="gmap_no" value="no" /> {$lang.no}</label>
					
					<script type="text/javascript">
					{literal}
					$('#gmap_uncheck').click(function(){
						$('#search_gmap_td input').attr('checked', false);
					});
					{/literal}
					</script>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsSearchField'}
			
			<tr>
				<td class="name">{$lang.status}</td>
				<td class="field">
					<select id="search_status" style="width: 200px;">
						<option value="">- {$lang.all} -</option>
						<option value="active">{$lang.active}</option>
						<option value="approval">{$lang.approval}</option>
					</select>
				</td>
			</tr>
			<tr>
				<td></td>
				<td class="field">
					<input type="submit" class="button lang_add" value="{$lang.search}" id="search_button" />
					<input type="button" class="button" value="{$lang.reset}" id="reset_search_button" />
			
					<a class="cancel" href="javascript:void(0)" onclick="show('search')">{$lang.cancel}</a>
				</td>
			</tr>
			</table>
			</form>
			
			{include file='blocks'|cat:$smarty.const.RL_DS|cat:'m_block_end.tpl'}
		</div>
		
		<script type="text/javascript">
		{literal}
		
		var search = new Array();
		var cookie_filters = '';

		$(document).ready(function(){
			
			if ( readCookie('listing_fields_sc') )
			{
				$('#search').show();
				cookie_filters = readCookie('listing_fields_sc').split(',');

				for (var i in cookie_filters)
				{
					if ( typeof(cookie_filters[i]) == 'string' )
					{
						var item = cookie_filters[i].split('||');
						if ( item[0] != 'undefined' && item[0] != '' )
						{
							if ( item[0] == 'Required' )
							{
								$('#search input').each(function(){
									var val = item[1] == 1 ? 'yes' : 'no';
									if ( $(this).attr('name') == 'search_required' && $(this).val() == val )
									{
										$(this).attr('checked', true);
									}
								});
							}
							else if ( item[0] == 'Map' )
							{
								$('#search input').each(function(){
									var val = item[1] == 1 ? 'yes' : 'no';
									if ( $(this).attr('name') == 'search_gmap' && $(this).val() == val )
									{
										$(this).attr('checked', true);
									}
								});
							}
							else
							{
								$('#search_'+item[0].toLowerCase()).selectOptions(item[1]);
							}
						}
					}
				}
			}
			
			$('#search_form').submit(function(){
				createCookie('listing_fields_pn', 0, 1);
				
				search = new Array();
				search.push( new Array('Name', $('#search_name').val()) );
				search.push( new Array('Type', $('#search_type').val()) );
				
				var required = $('input[name=search_required]:checked').val();
				search.push( new Array('Required', required == 'yes' ? 1 : required == 'no' ? 0 : '') );
				
				var map = $('input[name=search_gmap]:checked').val();
				search.push( new Array('Map', map == 'yes' ? 1 : map == 'no' ? 0 : '') );
				search.push( new Array('Status', $('#search_status').val()) );
				
				{/literal}{rlHook name='apTplListingFieldsSearchJS'}{literal}
				
				search.push( new Array('action', 'search') );
				
				// save search criteria
				var save_search = new Array();
				for(var i in search)
				{
					if ( search[i][1] != '' && search[i][1] != undefined )
					{
						save_search.push(search[i][0]+'||'+search[i][1]);
					}
				}
				
				createCookie('listing_fields_sc', save_search, 1);
				
				listingFieldsGrid.filters = search;
				listingFieldsGrid.reload();
			});
			
			$('#reset_search_button').click(function(){
				eraseCookie('listing_fields_sc');
				listingFieldsGrid.reset();
				
				$("#search select option[value='']").attr('selected', true);
				$("#search input[type=text]").val('');
				$("#search input").each(function(){
					if ( $(this).attr('type') == 'radio' )
					{
						$(this).attr('checked', false);
					}
				});
			});
			
		});
		
		{/literal}
		</script>
		<!-- search end -->
	{/if}
	
</div>

{if $smarty.get.action}

	{assign var='sPost' value=$smarty.post}

	<!-- add new field -->
	{include file='blocks'|cat:$smarty.const.RL_DS|cat:'m_block_start.tpl'}
	<form action="{$rlBaseC}action={if $smarty.get.action == 'add'}add{elseif $smarty.get.action == 'edit'}edit&amp;field={$smarty.get.field}{/if}" method="post">
		<input type="hidden" name="submit" value="1" />
		{if $smarty.get.action == 'edit'}
			<input type="hidden" name="fromPost" value="1" />
		{/if}
		<table class="form">
		<tr>
			<td class="name"><span class="red">*</span>{$lang.key}</td>
			<td class="field">
				<input {if $smarty.get.action == 'edit'}readonly="readonly"{/if} class="{if $smarty.get.action == 'edit'}disabled{/if}" name="key" type="text" style="width: 150px;" value="{$sPost.key}" maxlength="30" />
			</td>
		</tr>
		
		<tr>
			<td class="name"><span class="red">*</span>{$lang.name}</td>
			<td class="field">
				{if $allLangs|@count > 1}
					<ul class="tabs">
						{foreach from=$allLangs item='language' name='langF'}
						<li lang="{$language.Code}" {if $smarty.foreach.langF.first}class="active"{/if}>{$language.name}</li>
						{/foreach}
					</ul>
				{/if}
				
				{foreach from=$allLangs item='language' name='langF'}
					{if $allLangs|@count > 1}<div class="tab_area{if !$smarty.foreach.langF.first} hide{/if} {$language.Code}">{/if}
					<input type="text" name="name[{$language.Code}]" value="{$sPost.name[$language.Code]}" maxlength="350" />
					{if $allLangs|@count > 1}
							<span class="field_description_noicon">{$lang.name} (<b>{$language.name}</b>)</span>
						</div>
					{/if}
				{/foreach}
			</td>
		</tr>
		
		<tr>
			<td class="name">{$lang.description}</td>
			<td class="field">
				{if $allLangs|@count > 1}
					<ul class="tabs">
						{foreach from=$allLangs item='language' name='langF'}
						<li lang="{$language.Code}" {if $smarty.foreach.langF.first}class="active"{/if}>{$language.name}</li>
						{/foreach}
					</ul>
				{/if}
				
				{foreach from=$allLangs item='language' name='langF'}
					{if $allLangs|@count > 1}<div class="tab_area{if !$smarty.foreach.langF.first} hide{/if} {$language.Code}">{/if}
					<textarea cols="" rows="" name="description[{$language.Code}]">{$sPost.description[$language.Code]}</textarea>
					{if $allLangs|@count > 1}</div>{/if}
				{/foreach}
			</td>
		</tr>
		
		<tr>
			<td class="name">{$lang.required_field}</td>
			<td>
				{if $sPost.required == '1'}
					{assign var='required_yes' value='checked="checked"'}
				{elseif $sPost.required == '0'}
					{assign var='required_no' value='checked="checked"'}
				{else}
					{assign var='required_no' value='checked="checked"'}
				{/if}
				<label><input {$required_yes} type="radio" name="required" value="1" /> {$lang.yes}</label>
				<label><input {$required_no} type="radio" name="required" value="0" /> {$lang.no}</label>
			</td>
		</tr>
		
		<tr>
			<td class="name">{$lang.google_map}</td>
			<td class="field">
				{if $sPost.map == '1'}
					{assign var='map_yes' value='checked="checked"'}
				{elseif $sPost.map == '0'}
					{assign var='map_no' value='checked="checked"'}
				{else}
					{assign var='map_no' value='checked="checked"'}
				{/if}
				
				<table>
				<tr>
					<td>
						<label><input {$map_yes} type="radio" name="map" value="1" /> {$lang.yes}</label>
						<label><input {$map_no} type="radio" name="map" value="0" /> {$lang.no}</label>
					</td>
					<td>
						<span class="field_description">{$lang.use_for_displaing_map}</span>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		
		<tr>
			<td class="name">{$lang.show_on}</td>
			<td class="field">
				<label><input {if isset($sPost.add_page)}checked="checked"{else}{if empty($sPost)}checked="checked"{/if}{/if} type="checkbox" name="add_page" /> {$lang.add_page}</label>
				<label><input {if isset($sPost.details_page)}checked="checked"{else}{if empty($sPost)}checked="checked"{/if}{/if} type="checkbox" name="details_page" /> {$lang.details_page}</label>
			</td>
		</tr>
		
		{rlHook name='apTplListingFieldsForm'}
		
		<tr>
			<td class="name">{$lang.status}</td>
			<td class="field">
				<select name="status">
					<option value="active" {if $sPost.status == 'active'}selected="selected"{/if}>{$lang.active}</option>
					<option value="approval" {if $sPost.status == 'approval'}selected="selected"{/if}>{$lang.approval}</option>
				</select>
			</td>
		</tr>
		
		<tr>
			<td class="name"><span class="red">*</span>{$lang.field_type}</td>
			<td class="field">
				<select {if $smarty.get.action == 'edit'}disabled="disabled"{/if} onchange="field_types(this.value);" name="type" class="{if $smarty.get.action == 'edit'}disabled{/if}">
					<option value="">{$lang.select_field_type}</option>
					{foreach from=$l_types item='lType' key='key'}
						<option {if $sPost.type == $key}selected="selected"{/if} value="{$key}">{$lType}</option>
					{/foreach}
				</select>
				{if $smarty.get.action == 'edit'}
					<input type="hidden" name="type" value="{$sPost.type}" />
				{/if}
				
				{if $smarty.get.action == 'edit' && $field_info.Key|in_array:$sys_fields}
				<span class="field_description">{$lang.system_field_notice}</span>
				{/if}
			</td>
		</tr>
		</table>
		
		<!-- additional options -->
		<div id="additional_options">
	
		<script type="text/javascript">
		var langs_list = Array(
		{foreach from=$allLangs item='languages' name='lF'}
		'{$languages.Code}|{$languages.name}'{if !$smarty.foreach.lF.last},{/if}
		{/foreach}
		);
		</script>
		
		<!-- text field -->
		{assign var='textDefault' value=$sPost.text.default}
		<div id="field_text" class="hide">
			<table class="form">
			{foreach from=$allLangs item='languages' name='lang_foreach'}
			{assign var='lCode' value=$languages.Code}
			<tr>
				<td class="name">
					<div style="margin-left: 10px;">{$lang.default_value} <span class="green_10">(<b>{$languages.name}</b>)</span></div>
				</td>
				<td class="field">
					<input name="text[default][{$languages.Code}]" type="text" style="width: 250px;" value="{$textDefault.$lCode}" maxlength="100" />
				</td>
			</tr>
			{/foreach}
			
			{assign var='text_cond' value=$sPost.text}
			<tr>
				<td class="name">{$lang.check_condition}</td>
				<td class="field">
					<select name="text[condition]">
						<option value="">- {$lang.condition} -</option>
						{foreach from=$l_cond item='condition' key='cKey'}
							<option {if $text_cond.condition == $cKey}selected="selected"{/if} value="{$cKey}">{$condition}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			</table>
			
			<div id="text_multilingual" {if $text_cond.condition}class="hide"{/if}>
				<table class="form">
				<tr>
					<td class="name">{$lang.multilingual}</td>
					<td class="field">
						{if $sPost.text.multilingual == '1'}
							{assign var='text_multilingual_yes' value='checked="checked"'}
						{elseif $sPost.text.multilingual == '0'}
							{assign var='text_multilingual_no' value='checked="checked"'}
						{else}
							{assign var='text_multilingual_no' value='checked="checked"'}
						{/if}
						
						<label><input {$text_multilingual_yes} type="radio" name="text[multilingual]" value="1" /> {$lang.yes}</label>
						<label><input {$text_multilingual_no} type="radio" name="text[multilingual]" value="0" /> {$lang.no}</label>
					</td>
				</tr>
				</table>
			</div>
			
			<table class="form">
			<tr>
				<td class="name">{$lang.maxlength}</td>
				<td class="field">
					<input class="numeric" name="text[maxlength]" type="text" style="width: 50px; text-align: center;" value="{$sPost.text.maxlength}" maxlength="3" /> <span class="field_description">{$lang.default_text_value_des}</span>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsFormText'}
			
			</table>
			
			<script type="text/javascript">
			{literal}
			
			$(document).ready(function(){
				$('select[name="text[condition]"]').change(function(){
					var val = $(this).val();
					
					if ( val )
					{
						$('#text_multilingual').slideUp();
						$('input[name="text[multilingual]"][value=0]').prop('checked', true);
					}
					else
					{
						$('#text_multilingual').slideDown();
					}
				});
			});
			
			{/literal}
			</script>
		</div>
		<!-- text field end -->
		
		<!-- textarea field -->
		{assign var='textarea' value=$sPost.textarea}
			<div id="field_textarea" class="hide">
			<table class="form">
			<tr>
				<td class="name">{$lang.maxlength}</td>
				<td class="field">
					<input class="numeric" name="textarea[maxlength]" type="text" style="width: 50px; text-align: center;" value="{$textarea.maxlength}" maxlength="4" /> <span class="field_description">{$lang.default_textarea_value_des}</span>
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.multilingual}</td>
				<td class="field">
					{if $sPost.textarea.multilingual == '1'}
						{assign var='multilingual_yes' value='checked="checked"'}
					{elseif $sPost.textarea.multilingual == '0'}
						{assign var='multilingual_no' value='checked="checked"'}
					{else}
						{assign var='multilingual_no' value='checked="checked"'}
					{/if}
					
					<label><input {$multilingual_yes} type="radio" name="textarea[multilingual]" value="1" /> {$lang.yes}</label>
					<label><input {$multilingual_no} type="radio" name="textarea[multilingual]" value="0" /> {$lang.no}</label>
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.html_editor}</td>
				<td class="field">
					{if $sPost.textarea.html == '1'}
						{assign var='html_yes' value='checked="checked"'}
					{elseif $sPost.textarea.html == '0'}
						{assign var='html_no' value='checked="checked"'}
					{else}
						{assign var='html_no' value='checked="checked"'}
					{/if}
					
					<label><input {$html_yes} type="radio" name="textarea[html]" value="1" /> {$lang.yes}</label>
					<label><input {$html_no} type="radio" name="textarea[html]" value="0" /> {$lang.no}</label>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsFormTextarea'}
			
			</table>
		</div>
		<!-- textarea field end -->
		
		<!-- number field -->
		{assign var='number' value=$sPost.number}
		<div id="field_number" class="hide">
			<table class="form">
			<tr>
				<td class="name">{$lang.minumber}</td>
				<td class="field">
					<input class="numeric" name="number[min_number]" type="text" style="width: 60px; text-align: center;" value="{$number.min_number}" maxlength="8" />
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.maxnumber}</td>
				<td class="field">
					<input class="numeric" name="number[max_number]" type="text" style="width: 60px; text-align: center;" value="{$number.max_number}" maxlength="8" />
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsNumber'}
			
			</table>
		</div>
		<!-- number field end -->
		
		<!-- date field -->
		{assign var='date' value=$sPost.date}
		<div id="field_date" class="hide">
			<table class="form">
			<tr>
				<td class="name"><span class="red">*</span>{$lang.mode}</td>
				<td class="field">
					<label><input {if $date.mode == 'single'}checked="checked"{/if} type="radio" name="date[mode]" value="single" /> {$lang.single_date}</label>
					<label><input {if $date.mode == 'multi'}checked="checked"{/if} type="radio" name="date[mode]" value="multi" /> {$lang.time_period}</label>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsDate'}
			
			</table>
		</div>
		<!-- date field end -->
		
		<!-- boolean field -->
		{if $sPost.bool.default == '1'}
			{assign var='bool_default_yes' value='checked="checked"'}
		{elseif $sPost.required == '0'}
			{assign var='bool_default_no' value='checked="checked"'}
		{else}
			{assign var='bool_default_no' value='checked="checked"'}
		{/if}
		<div id="field_bool" class="hide">
			<table class="form">
			<tr>
				<td class="name">{$lang.default_value}</td>
				<td class="field">
					<label><input {$bool_default_yes} type="radio" name="bool[default]" value="1" /> {$lang.yes}</label>
					<label><input {$bool_default_no} type="radio" name="bool[default]" value="0" /> {$lang.no}</label>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsBool'}
			
			</table>
		</div>
		<!-- boolean field end -->
		
		<!-- mixed field -->
		<div id="field_mixed" class="hide">
			<script type="text/javascript">
			var mixed_step = 1;
			</script>
			<table class="form">
			
			{rlHook name='apTplListingFieldsMixed'}
			
			<tr>
				<td class="name">{$lang.bind_data_format}</td>
				<td class="field">
					<select id="dd_mixed_block" name="mixed_data_format" class="data_format">
						<option value="0">{$lang.select}</option>
						{foreach from=$data_formats item='format'}
						<option value="{$format.Key}"{if $format.Key == $sPost.mixed_data_format} selected="selected"{/if}>{$format.name|strip_tags}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			</table>
			
			<div id="mixed_block" {if $sPost.mixed_data_format}class="hide"{/if}>
			<table class="form" style="margin: 10px 0 0;">
			<tr>
				<td class="name">{$lang.field_items}</td>
				<td class="field">
					<table id="mixed">
					{if $sPost.mixed}
						{foreach from=$sPost.mixed item='selectItem' key='selectKey'}
						{if $selectKey != 'default'}
						<tr id="mixed_{$selectKey}">
							<td>
								{foreach from=$allLangs item='languages' name='lang_foreach'}
									{assign var='lCode' value=$languages.Code}
									<div><input type="text" class="margin float" value="{$selectItem.$lCode}" name="mixed[{$selectKey}][{$languages.Code}]" /><span class="field_description">{$lang.item_value} <span class="green_10">(<b>{$languages.name}</b>)</span></span></div>
								{/foreach}
							</td>
							<td style="padding: 3px 10px 0 10px;">
								<input {if $sPost.mixed.default == $selectKey}checked="checked"{/if} id="mixed_def_{$selectKey}" type="radio" name="mixed[default]" value="{$selectKey}" /> <label for="mixed_def_{$selectKey}">{$lang.default}</label>
							</td>
							<td>
								<a class="delete_item" href="javascript:void(0)" onclick="$('#mixed_{$selectKey}').remove('');">{$lang.remove}</a>
								<script type="text/javascript">
								if (mixed_step <= {$selectKey})
									mixed_step = {$selectKey} + 1;
								</script>
							</td>
						</tr>
						{/if}
						{/foreach}
					{/if}
					</table>
					
					<div class="add_item"><a href="javascript:void(0)" onclick="field_build('mixed', langs_list );">{$lang.add_field_item}</a></div>
				</td>
			</tr>
			</table>
			</div>
		</div>
		<!-- mixed field end -->
		
		<!-- dropdown list field -->
		<div id="field_select" class="hide">
			<script type="text/javascript">
			var select_step = 1;
			</script>
			<table class="form">
			
			{rlHook name='apTplListingFieldsDropdown'}
			
			<tr>
				<td class="name">{$lang.bind_data_format}</td>
				<td class="field">
					<select id="dd_select_block" name="data_format" class="data_format">
						<option value="0">{$lang.select}</option>
						{foreach from=$data_formats item='format'}
						<option value="{$format.Key}"{if $format.Key == $sPost.data_format} selected="selected"{/if}>{$format.name|strip_tags}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			</table>
			
			<div id="select_block" {if $sPost.data_format}class="hide"{/if}>
			<table class="form" style="margin: 10px 0 0;">
			<tr>
				<td class="name">{$lang.field_items}</td>
				<td class="field">
					<table id="select">
					{if $sPost.select}
						{foreach from=$sPost.select item='selectItem' key='selectKey'}
						{if $selectKey != 'default'}
						<tr id="select_{$selectKey}">
							<td>
								{foreach from=$allLangs item='languages' name='lang_foreach'}
									{assign var='lCode' value=$languages.Code}
									<div><input type="text" class="float margin" value="{$selectItem.$lCode}" name="select[{$selectKey}][{$languages.Code}]" /><span class="field_description">{$lang.item_value} <span class="green_10">(<b>{$languages.name}</b>)</span></span></div>
								{/foreach}
							</td>
							<td style="padding: 3px 10px 0 10px;">
								<input {if $sPost.select.default == $selectKey}checked="checked"{/if} id="select_def_{$selectKey}" type="radio" name="select[default]" value="{$selectKey}" /> <label for="select_def_{$selectKey}">{$lang.default}</label>
							</td>
							<td>
								<a class="delete_item" href="javascript:void(0)" onclick="$('#select_{$selectKey}').remove('');">{$lang.remove}</a>
								<script type="text/javascript">
								if (select_step <= {$selectKey})
									select_step = {$selectKey} + 1;
								</script>
							</td>
						</tr>
						{/if}
						{/foreach}
					{/if}
					</table>
					
					<div class="add_item"><a href="javascript:void(0)" onclick="field_build('select', langs_list );">{$lang.add_field_item}</a></div>
				</td>
			</tr>
			</table>
			</div>
		</div>
		<!-- dropdown list field end -->
		
		<!-- radio set field -->
		<div id="field_radio" class="hide">
			<script type="text/javascript">
			var radio_step = 1;
			</script>
			<table class="form">
			
			{rlHook name='apTplListingFieldsRadio'}
			
			<tr>
				<td class="name">{$lang.bind_data_format}</td>
				<td class="field">
					<select id="dd_radio_block" name="data_format" class="data_format margin">
						<option value="0">{$lang.select}</option>
						{foreach from=$data_formats item='format'}
						<option value="{$format.Key}"{if $format.Key == $sPost.data_format} selected="selected"{/if}>{$format.name|strip_tags}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			</table>
			
			<div id="radio_block" {if $sPost.data_format}class="hide"{/if}>
			<table class="form" style="margin: 10px 0 0;">
			<tr>
				<td class="name">{$lang.field_items}</td>
				<td class="field">
					<table id="radio">
					{if $sPost.radio}
						{foreach from=$sPost.radio item='radioItem' key='radioKey'}
						{if $radioKey != 'default'}
						<tr id="radio_{$radioKey}">
							<td>
								{foreach from=$allLangs item='languages' name='lang_foreach'}
									{assign var='lCode' value=$languages.Code}
									<div><input type="text" class="float margin" value="{$radioItem.$lCode}" name="radio[{$radioKey}][{$languages.Code}]" /><span class="field_description">{$lang.item_value} <span class="green_10">(<b>{$languages.name}</b>)</span></span></div>
								{/foreach}
							</td>
							<td style="padding: 3px 10px 0 10px;">
								<input {if $sPost.radio.default == $radioKey}checked="checked"{/if} id="radio_def_{$radioKey}" type="radio" name="radio[default]" value="{$radioKey}" /> <label for="radio_def_{$radioKey}">{$lang.default}</label>
							</td>
							<td>
								<a class="delete_item" href="javascript:void(0)" onclick="$('#radio_{$radioKey}').remove('');">{$lang.remove}</a>
								<script type="text/javascript">
								if (radio_step <= {$radioKey})
									radio_step = {$radioKey} + 1;
								</script>
							</td>
						</tr>
						{/if}
						{/foreach}
					{/if}
					</table>
					
					<div class="add_item"><a href="javascript:void(0)" onclick="field_build('radio', langs_list );">{$lang.add_field_item}</a></div>
				</td>
			</tr>
			</table>
			</div>
		</div>
		<!-- radio set field end -->
		
		<!-- checkbox set field -->	
		<div id="field_checkbox" class="hide">
			<script type="text/javascript">
			var checkbox_step = 1;
			</script>
			<table class="form">
			
			{rlHook name='apTplListingFieldsCheckbox'}
			
			<tr>
				<td class="name">{$lang.number_of_columns}</td>
				<td>
					<input type="text" style="text-align: center;width: 40px;" maxlength="2" value="{if $sPost.column_number}{$sPost.column_number}{else}3{/if}" name="column_number" />
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.show_all_options}</td>
				<td>
					{assign var='checkbox_field' value='show_tils'}
				
					{if $sPost.$checkbox_field == '1'}
						{assign var=$checkbox_field|cat:'_yes' value='checked="checked"'}
					{elseif $sPost.$checkbox_field == '0'}
						{assign var=$checkbox_field|cat:'_no' value='checked="checked"'}
					{else}
						{assign var=$checkbox_field|cat:'_yes' value='checked="checked"'}
					{/if}
					
					<input {$show_tils_yes} type="radio" id="{$checkbox_field}_yes" name="{$checkbox_field}" value="1" /> <label for="{$checkbox_field}_yes">{$lang.yes}</label>
					<input {$show_tils_no} type="radio" id="{$checkbox_field}_no" name="{$checkbox_field}" value="0" /> <label for="{$checkbox_field}_no">{$lang.no}</label>
					
					<span class="field_description">{$lang.show_all_options_hint}</span>
				</td>
			</tr>
			<tr>
				<td class="name">{$lang.bind_data_format}</td>
				<td>
					<select id="dd_checkbox_block" name="data_format" class="data_format">
						<option value="0">{$lang.select}</option>
						{foreach from=$data_formats item='format'}
						<option value="{$format.Key}"{if $format.Key == $sPost.data_format} selected="selected"{/if}>{$format.name|strip_tags}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			</table>
			
			<div id="checkbox_block" {if $sPost.data_format}class="hide"{/if}>
			<table class="form" style="margin: 10px 0 0;">
			<tr>
				<td class="name">{$lang.field_items}</td>
				<td class="field">
					<table id="checkbox">
					{if $sPost.checkbox}
						{foreach from=$sPost.checkbox item='checkboxItem' key='checkboxKey'}
						{assign var='checkbox' value=$sPost.checkbox}
						{assign var='checkboxIter' value=$checkbox.$checkboxKey}
						{if $checkboxKey != 'default'}
						<tr id="checkbox_{$checkboxKey}">
							<td>
								{foreach from=$allLangs item='languages' name='lang_foreach'}
									{assign var='lCode' value=$languages.Code}
									<div><input type="text" class="margin float" value="{$checkboxItem.$lCode}" name="checkbox[{$checkboxKey}][{$languages.Code}]" /><span class="field_description">{$lang.item_value} <span class="green_10">(<b>{$languages.name}</b>)</span></span></div>
								{/foreach}
							</td>
							<td style="padding: 3px 10px 0 10px;">
								<input {if $checkboxIter.default == $checkboxKey}checked="checked"{/if} id="checkbox_def_{$checkboxKey}" type="checkbox" name="checkbox[{$checkboxKey}][default]" value="{$checkboxKey}" /> <label for="checkbox_def_{$checkboxKey}">{$lang.default}</label>
							</td>
							<td>
								<a class="delete_item" href="javascript:void(0)" onclick="$('#checkbox_{$checkboxKey}').remove('');">{$lang.remove}</a>
								<script type="text/javascript">
								if (checkbox_step <= {$checkboxKey})
									checkbox_step = {$checkboxKey} + 1;
								</script>
							</td>
						</tr>
						{/if}
						{/foreach}
					{/if}
					</table>
					
					<div class="add_item"><a href="javascript:void(0)" onclick="field_build('checkbox', langs_list );">{$lang.add_field_item}</a></div>
				</td>
			</tr>
			</table>
			</div>
		</div>
		<!-- checkbox set field end -->
		
		<!-- image field -->
		{assign var='image' value=$sPost.image}
		<div id="field_image" class="hide">
			<table class="form">
			<tr>
				<td class="name">{$lang.resize_type}</td>
				<td class="field">
					<select onchange="resize_action($(this).val());" name="image[resize_type]">
						<option value="">- {$lang.resize_type} -</option>
						{foreach from=$l_resize item='resize' key='resKey'}
							<option value="{$resKey}" {if $resKey == $sPost.image.resize_type}selected="selected"{/if}>{$resize}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			
			<tr>
				<td class="name">{$lang.resolution}</td>
				<td class="field">
					<table>
					<tr>
						<td>
							<small>{$lang.width}: </small>
						</td>
						<td>
							<input readonly="readonly" id="resW" class="margin numeric" name="image[width]" type="text" style="width: 40px; text-align: center;" value="{$sPost.image.width}" maxlength="4" />
						</td>
					</tr>
					<tr>
						<td>
							<small>{$lang.height}: </small>
						</td>
						<td>
							<input readonly="readonly" id="resH" class="margin numeric" name="image[height]" type="text" style="width: 40px; text-align: center;" value="{$sPost.image.height}" maxlength="4" />
						</td>
					</tr>
					</table>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsImage'}
			
			</table>
		</div>
		<!-- image field end -->
		
		<!-- file storage field -->
		{assign var='image' value=$sPost.image}
		<div id="field_file" class="hide">
			<table class="form">
			<tr>
				<td class="name"><span class="red">*</span>{$lang.file_type}</td>
				<td class="field">
					<select name="file[type]">
						<option value="">- {$lang.file_type} -</option>
						{foreach from=$l_file_types item='fTypes' key='ftKey'}
							<option value="{$ftKey}" {if $ftKey == $sPost.file.type}selected="selected"{/if}>{$fTypes.name} ({$fTypes.ext})</option>
						{/foreach}
					</select>
				</td>
			</tr>
			
			{rlHook name='apTplListingFieldsFile'}
			
			</table>
		</div>
		<!-- file storage field end -->
		
		<!-- agreement field -->
		<div id="field_accept" class="hide">
			<table class="form">
			
			{rlHook name='apTplListingFieldsAgreement'}
			
			{foreach from=$allLangs item='languages' name='lang_foreach'}
			{assign var='accept' value=$sPost.accept}
			{assign var='lCode' value=$languages.Code}
			<tr>
				<td class="name">
					<div style="margin-left: 10px;"><span class="red">*</span>{$lang.agreement_text} <span class="green_10">(<b>{$languages.name}</b>)</span></div>
				</td>
				<td class="field">
					<textarea rows="5" cols="" name="accept[{$languages.Code}]">{$accept.$lCode}</textarea>
				</td>
			</tr>
			{/foreach}
			</table>
		</div>
		<!-- agreement field -->
		
		{rlHook name='apTplListingFieldsFormBottom'}
		
		</div>
		<!-- additional options end -->
		
		{assign var='no_expand' value=false}
		{if $smarty.get.action == 'edit' && $field_info.Key|in_array:$sys_fields}
			{assign var='no_expand' value=true}
		{/if}
		
		<!-- additional JS -->
		{if $sPost.type != false && !$no_expand}
		<script type="text/javascript">
			field_types('{$sPost.type}');
		</script>	
		{/if}
		
		{if $sPost.image.resize_type}
		<script type="text/javascript">
			resize_action('{$sPost.image.resize_type}');
		</script>	
		{/if}
		<!-- additional JS end -->
		
		<table class="form">
		<tr>
			<td class="no_divider"></td>
			<td class="field">
				<input type="submit" value="{if $smarty.get.action == 'edit'}{$lang.edit}{else}{$lang.add}{/if}" />
			</td>
		</tr>
		</table>
	</form>
	{include file='blocks'|cat:$smarty.const.RL_DS|cat:'m_block_end.tpl'}
	<!-- add new field end -->

{else}
	
	<!-- listing fields grid -->
	<div id="grid"></div>
	<script type="text/javascript">//<![CDATA[
	var listingFieldsGrid;
	
	{literal}
	$(document).ready(function(){
		
		listingFieldsGrid = new gridObj({
			key: 'listingFields',
			id: 'grid',
			ajaxUrl: rlUrlHome + 'controllers/listing_fields.inc.php?q=ext',
			defaultSortField: 'name',
			remoteSortable: true,
			title: lang['ext_listing_fields_manager'],
			filters: cookie_filters,
			fields: [
				{name: 'name', mapping: 'name', type: 'string'},
				{name: 'Type', mapping: 'Type'},
				{name: 'Required', mapping: 'Required'},
				{name: 'Add_page', mapping: 'Add_page'},
				{name: 'Details_page', mapping: 'Details_page'},
				{name: 'Map', mapping: 'Map'},
				{name: 'Arrange', mapping: 'Arrange'},
				{name: 'Status', mapping: 'Status'},
				{name: 'Key', mapping: 'Key'}
			],
			columns: [
				{
					header: lang['ext_name'],
					dataIndex: 'name',
					width: 60,
					id: 'rlExt_item_bold'
				},{
					id: 'rlExt_item',
					header: lang['ext_type'],
					dataIndex: 'Type',
					width: 30
				},{
					header: lang['ext_required_field'],
					dataIndex: 'Required',
					width: 17,
					editor: new Ext.form.ComboBox({
						store: [
							['1', lang['ext_yes']],
							['0', lang['ext_no']]
						],
						displayField: 'value',
						valueField: 'key',
						emptyText: lang['ext_not_available'],
						typeAhead: true,
						mode: 'local',
						triggerAction: 'all',
						selectOnFocus:true
					}),
					renderer: function(val){
						return '<span ext:qtip="'+lang['ext_click_to_edit']+'">'+val+'</span>';
					}
				},{
					header: lang['ext_google_map'],
					dataIndex: 'Map',
					width: 17,
					editor: new Ext.form.ComboBox({
						store: [
							['1', lang['ext_yes']],
							['0', lang['ext_no']]
						],
						displayField: 'value',
						valueField: 'key',
						emptyText: lang['ext_not_available'],
						typeAhead: true,
						mode: 'local',
						triggerAction: 'all',
						selectOnFocus: true
					}),
					renderer: function(val){
						return '<span ext:qtip="'+lang['ext_click_to_edit']+'">'+val+'</span>';
					}
				},{
					header: lang['ext_status'],
					dataIndex: 'Status',
					width: 15,
					editor: new Ext.form.ComboBox({
						store: [
							['active', lang['ext_active']],
							['approval', lang['ext_approval']]
						],
						displayField: 'value',
						valueField: 'key',
						typeAhead: true,
						mode: 'local',
						triggerAction: 'all',
						selectOnFocus:true
					}),
					renderer: function(val){
						return '<span ext:qtip="'+lang['ext_click_to_edit']+'">'+val+'</span>';
					}
				},{
					header: lang['ext_actions'],
					width: 70,
					fixed: true,
					dataIndex: 'Key',
					sortable: false,
					renderer: function(data, ext, row) {
						var out = "<center>";
						var splitter = false;
						var mess = '';
						
						if ( rights[cKey].indexOf('edit') >= 0 )
						{
							out += "<a href='"+rlUrlHome+"index.php?controller="+controller+"&action=edit&field="+data+"'><img class='edit' ext:qtip='"+lang['ext_edit']+"' src='"+rlUrlHome+"img/blank.gif' /></a>";
						}
						if ( rights[cKey].indexOf('delete') >= 0 )
						{
							if ( row.data.Arrange )
							{
								 mess = '<br /><br />'+lang['ext_field_in_type_arrange_warning'].replace('{type}', row.data.Arrange);
							}
							out += "<img class='remove' ext:qtip='"+lang['ext_delete']+"' src='"+rlUrlHome+"img/blank.gif' onclick='rlConfirm( \""+lang['ext_notice_delete_field']+mess+"\", \"xajax_deleteLField\", \""+Array(data)+"\", \"field_load\" )' />";
						}
						out += "</center>";
						
						return out;
					}
				}
			]
		});
		
		{/literal}{rlHook name='apTplListingFieldsGrid'}{literal}
		
		listingFieldsGrid.init();
		grid.push(listingFieldsGrid.grid);
		
	});
	{/literal}
	//]]>
	</script>
	<!-- listing fields grid end -->
	
	{rlHook name='apTplListingFieldsBottom'}

{/if}

<!-- listing fields tpl end -->